package com.andrew.controller;

import cn.hutool.json.JSONUtil;
import com.andrew.common.ReturnResult;
import com.andrew.idempotent.Idempotent;
import com.andrew.interceptor.AutoIdempotent;
import com.andrew.model.QueryInfo;
import com.andrew.service.TokenService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private TokenService tokenService;

    @GetMapping("/test")
    public String  test(){
        return "123456";
    }

    @GetMapping("/getToken")
    public String  getToken(){
        String token = tokenService.createToken();
        return JSONUtil.toJsonStr(ReturnResult.withSuccess(token));
    }

    @Idempotent(key = "name", expire = 30)
    @PostMapping("/testIdempotence2")
    public String testIdempotence2(@RequestBody QueryInfo queryInfo) {
        return JSONUtil.toJsonStr(ReturnResult.withSuccess());
    }

    @AutoIdempotent
    @PostMapping("/testIdempotence")
    public String testIdempotence() {
        return JSONUtil.toJsonStr(ReturnResult.withSuccess());
    }
}
